<?
// Get recent additions
$optID = $uriOptID;
if (!empty($optID)) {
	
	// Get recent additions for this option only
	// Get recent addition for the sub category 
	$sqlR = "SELECT *
		FROM ss_resource R
		LEFT JOIN ss_resourceLink L ON R.ID = L.ResourceID
		WHERE L.Sub2CatID = '$SubCatID' AND
		L.OptionID = '$optID' AND
		R.Visible = 1 AND
		R.Score > 0
		ORDER BY R.Score DESC
		LIMIT 4";
	$resultR = mysql_db_query($dbname,$sqlR);
	$rowsR = mysql_num_rows($resultR);
	//$linkOptID = "&optID=".$optID;
	$linkOptID = $optID;
} else {
	// Get recent addition for the sub category 
	$sqlR = "SELECT *
		FROM ss_resource R
		LEFT JOIN ss_resourceLink L ON R.ID = L.ResourceID
		WHERE L.Sub2CatID = '$SubCatID' AND
		R.Visible = 1 AND
		R.Score > 0
		ORDER BY R.Score DESC
		LIMIT 4";
	$resultR = mysql_db_query($dbname,$sqlR);
	$rowsR = mysql_num_rows($resultR);
}
if (!empty($rowsR)) {
	echo "<div class=\"midBar\">Most Popular Resources</div>\n";
	include("includes/listResources.php");
	if ($rowsT > $rowsR) {
		echo "<div align=\"right\"><img src=\"http://www.sonixshop.com/images/bullet_red.gif\">&nbsp;\n";
		//echo "<a href=\"/va/$SubCatID/$linkOptID\"><b>View all $rowsT resources</b></a></div>\n";
		echo "<a href=\"http://www.sonixshop.com/viewResourcesAll.php?subCatID=$SubCatID&optID=$linkOptID\"><b>View all $rowsT resources</b></a></div>\n";
	}
}	

$totalRows = $totalRows+$rowsR;
?>